package FIT::Document::Transformer::Red;

use FIT::Class;
use FIT::Document::Parser::Twig;

extends 'FIT::Document::Transformer::Base';

has actual => (is => 'ro', isa => 'Str');
has note   => (is => 'ro', isa => 'Str');

sub _transform {
    my $element = shift;
    my $actual  = $self->actual;
    my $note    = $self->note;
    $element->set_att(class => 'fit_wrong');
    return if !defined($actual) && !defined($note);

    die "Can't transform Red with both 'note' and 'actual'"
        if defined($actual) && defined($note);
    my $cell = $element->tag eq 'td'? $element : $element->first_cell;
    my $xml = $cell->sprint(1);
    if (defined($note)) { # note is defined

        $note = $self->escape($note);
        $xml .= qq{ <span class="fit_wrong_note">$note</span>};

    } else { # actual is defined

        $xml .=
            qq{ <span class="fit_wrong_note">expected </span>}.
            qq{<hr/>$actual <span class="fit_wrong_note">actual</span>};
    }
    $cell->set_inner_xml($xml);
}
